package com.acme.bankapp.domain.bank;

import com.acme.bankapp.exceptions.*;

/**
 * This abstract class implements Account interface
 * 
 * @author Anton Kotov
 * 
 */
public abstract class AbstractAccount implements Account {

	protected int id;
	protected double balance;

	public AbstractAccount(final int id, final double balance) {
		this.id = id;
		this.balance = balance;
	}

	public double getBalance() {
		return balance;
	}

	public void deposit(final double amount) {
		if (amount <= 0.) {
			throw new IllegalArgumentException();
		}

		balance += amount;
	}

	public void withdraw(final double amount) throws NotEnoughFundsException {
		if (amount <= 0.) {
			throw new IllegalArgumentException();
		}
		double maximumAmountToWithdraw = maximumAmountToWithdraw();
		if (amount > maximumAmountToWithdraw) {
			throw new NotEnoughFundsException("Failed to withdraw: "
					+ "trying to withdraw " + amount
					+ " funds. The maximum allowable value is "
					+ maximumAmountToWithdraw);
		}

		balance -= amount;
	}

	public String toString() {
		return Integer.toString(id);
	}

}
